package com.xm.servlet.reception_desk.index;

import com.google.gson.Gson;
import com.xm.entity.Commodity;
import com.xm.service.reception_desk.CommodityService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 查询更多商品
 * @author 康文程
 * @date 2023-12-28 上午 08:53
 */
@WebServlet("/more/commodity")
public class MoreCommodityServlet extends HttpServlet {
    private final CommodityService service = new CommodityService();
    /**
     * 查看更多商品
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        resp.setContentType("text/html;charset=UTF-8");
        String ids = req.getParameter("ids");
        System.out.println(ids);
        List<Commodity> commoditieList = service.searchByCommodityClassId(ids);
        Gson gson = new Gson();
        String json = gson.toJson(commoditieList);
        resp.getWriter().println(json);
    }
}
